# _*_ coding : utf-8 _*_
# @Time : 2022/8/8 19:41
# @Author : Moonquake
# @File : 13.百度翻译之详细翻译
# @Project : python
import urllib.request
import urllib.parse
url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
headers = {
'Accept':'*/*',
#'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Acs-Token':'1659942009950_1659959938051_Bkel7ztj79oh+hintsSW2lHzeXGnw68GTlbcnxi98agcLYYDPdf/tjFORfUtITJzfdmfuw8jwkrK9ZPHsg4OTxlC4TqP/v3JCD2VQ9hXM1BtU1gYAXcX/BIh6OkzCp/1T0jhdEYySxvuto+hOe/mWSkD1dpmgSrpciGCqX3KRKkcaCkLv6bDRnODA4H6hAcEXEQdrp14XW/snCMNtyvsszcbetO3YdEES5ED+iV7gOxaUMTblJrVVut0qUiWRLVr9sCSDyTEA4Y3d2DoaBS1Ww==',
'Connection':'keep-alive',
'Content-Length':'135',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'BAIDUID=030F2CCC1DA69DD334B395E575BD25F1:FG=1; BIDUPSID=030F2CCC1DA69DD3E694D56979142F81; PSTM=1653406764; ZFY=15W0TclpmlcOjjMYrRoi1hR7ZMuPUw0Neu6YK0UW5uA:C; BA_HECTOR=8h2g8k8gal2k8ga5842hr4tm1hf1de217; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1659942359,1659958916,1659961038; APPGUIDE_10_0_2=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; ab_sr=1.0.1_OWFiM2VlOTFiYTNlNTc0NzMyZjM2YmRjNTcxZDJlZmY3NDZiMjIyZjdmOWY1YjZjM2U0MGQ4ODI3ODc5ZjU4OTM5YWYwYzVjZmJmZGMzNWNiYTU0ZGEzN2IyYjhiNGQ4M2I5NDUwOTA2Mzk4MmM5Y2NmZjY2N2RiZTllYzNkOGQwMTEwZjRlMTE4NWVkOTI1MTYzODVjNjI0MjdiODRiYg==; H_PS_PSSID=36543_36755_36641_36726_37111_36413_36847_36955_36166_36917_36569_36746_37055_26350_36866_37022; delPer=0; PSINO=2; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1659961046',
'Host':'fanyi.baidu.com',
'Origin':'https://fanyi.baidu.com',
'Referer':'https://fanyi.baidu.com/?aldtype=16047',
'Sec-Fetch-Dest':'empty',
'Sec-Fetch-Mode':'cors',
'Sec-Fetch-Site':'same-origin',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0',
'X-Requested-With':'XMLHttpRequest',
}

data = {
    'from': 'en',
    'to': 'zh',
    'query': 'love',
    'transtype': 'realtime',
    'simple_means_flag': '3',
    'sign': '198772.518981',
    'token': '913b3f11dd771bd671823014062815d4',
    'domain': 'common'
}
data = urllib.parse.urlencode(data).encode('utf-8')
request= urllib.request.Request(url=url,data=data,headers=headers)
response= urllib.request.urlopen(request)

# 获取响应的数据
content = response.read().decode('utf-8')
# 序列化
import json
obj=json.loads(content)
print(obj)